package com.nas.crocus.dao.impl;

import java.util.Collection;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.nas.crocus.dao.AlojamientoDao;
import com.nas.crocus.domain.Alojamiento;

@Repository
public class AlojamientoDaoImpl implements AlojamientoDao {

    @Autowired
    private SessionFactory sessionFactory;
    
    @Override
    public Collection<Alojamiento> buscarPorEventoId(Long eventoId) {
        Session session = sessionFactory.getCurrentSession();        
        return session.createCriteria(Alojamiento.class).add( Restrictions.eq("evento.id", eventoId) ).list();
    }

    @Override
    public Alojamiento obtener(Long alojamientoId) {
        return (Alojamiento) sessionFactory.getCurrentSession().createCriteria(Alojamiento.class).add( Restrictions.eq("id", alojamientoId)).uniqueResult();
    }
    

}
